package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.commons.page.MyBatisPlusPageConverter;
import com.smile.commons.page.R;
import com.smile.model.dto.request.AddPoliceWarningsRequestDTO;
import com.smile.model.dto.request.EditPoliceWarningsRequestDTO;
import com.smile.model.dto.request.GetPoliceWarningsDetailsRequestDTO;
import com.smile.model.dto.request.GetPoliceWarningsListRequestDTO;
import com.smile.model.response.response.GetPoliceWarningsDetailsResponseDTO;
import com.smile.model.response.response.GetPoliceWarningsListResponseDTO;
import com.smile.model.request.AddPoliceWarningsRequest;
import com.smile.model.request.EditPoliceWarningsRequest;
import com.smile.model.request.GetPoliceWarningsDetailsRequest;
import com.smile.model.request.GetPoliceWarningsListRequest;
import com.smile.model.response.GetPoliceWarningsDetailsResponse;
import com.smile.model.response.GetPoliceWarningsListResponse;
import com.smile.service.PoliceWarningsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/policeWarnings")
public class PoliceWarningsController {
    @Autowired
    private PoliceWarningsService policeWarningsService;

    @PostMapping("/getPoliceWarningsList")
    public R<Page<GetPoliceWarningsListResponse>> getPoliceWarningsList(@RequestBody GetPoliceWarningsListRequest request) {
        GetPoliceWarningsListRequestDTO getPoliceWarningsListRequestDTO = BeanUtil.copyProperties(request, GetPoliceWarningsListRequestDTO.class);
        Page<GetPoliceWarningsListResponseDTO> page = policeWarningsService.getPoliceWarningsList(getPoliceWarningsListRequestDTO);
        return R.ok(MyBatisPlusPageConverter.convertPage(page, GetPoliceWarningsListResponse.class));
    }

    @PostMapping("/getPoliceWarningsDetails")
    public R<GetPoliceWarningsDetailsResponse> getPoliceWarningsDetails(@RequestBody GetPoliceWarningsDetailsRequest request) {
        GetPoliceWarningsDetailsRequestDTO getPoliceWarningsDetailsRequestDTO = BeanUtil.copyProperties(request, GetPoliceWarningsDetailsRequestDTO.class);
        GetPoliceWarningsDetailsResponseDTO getPoliceWarningsDetailsResponseDTO = policeWarningsService.getPoliceWarningsDetails(getPoliceWarningsDetailsRequestDTO);
        return R.ok(BeanUtil.copyProperties(getPoliceWarningsDetailsResponseDTO, GetPoliceWarningsDetailsResponse.class));
    }

    @PostMapping("/addPoliceWarnings")
    public R<Void> addPoliceWarnings(@RequestBody AddPoliceWarningsRequest addPoliceWarningsRequest) {
        AddPoliceWarningsRequestDTO addPoliceWarningsRequestDTO = BeanUtil.copyProperties(addPoliceWarningsRequest, AddPoliceWarningsRequestDTO.class);
        Boolean result = policeWarningsService.addPoliceWarnings(addPoliceWarningsRequestDTO);
        if (result) {
            return R.ok();
        } else {
            return R.fail();
        }
    }

    @PostMapping("/editPoliceWarnings")
    public R<Void> editPoliceWarnings(@RequestBody EditPoliceWarningsRequest editPoliceWarningsRequest) {
        EditPoliceWarningsRequestDTO editPoliceWarningsRequestDTO = BeanUtil.copyProperties(editPoliceWarningsRequest, EditPoliceWarningsRequestDTO.class);
        Boolean result = policeWarningsService.editPoliceWarnings(editPoliceWarningsRequestDTO);
        if (result) {

            return R.ok();
        } else {
            return R.fail();
        }
    }

}
